#include<stdio.h>
#include<stdlib.h>
typedef struct hourse{
    long v,id;
};
long n,i;
hourse tontan[100001],vuate[100001];
long trace[100001],rightTonTan,leftTonTan,rightVuaTe,leftVuaTe;
/************************************************/
int sosanh(const void *a,const void *b){
    return ((*((hourse*)a)).v-(*((hourse*)b)).v);
}
void input(){
    FILE *fp=fopen("RACE.INP","r");
    fscanf(fp,"%ld",&n);
    for(i=0;i<n;i++){
        tontan[i].id=i;
        fscanf(fp,"%ld",&tontan[i].v);
    }
    qsort(tontan,n,sizeof(hourse),sosanh);
    for(i=0;i<n;i++){
        vuate[i].id=i;
        fscanf(fp,"%ld",&vuate[i].v);
    }
    qsort(vuate,n,sizeof(hourse),sosanh);
    fclose(fp);   
    rightTonTan=rightVuaTe=n-1;
    leftTonTan=leftVuaTe=0;
}
int trai(){
    if(tontan[leftTonTan].v==vuate[leftVuaTe].v)return 0;
    else if(tontan[leftTonTan].v>vuate[leftVuaTe].v)return 1;
    return -1;
}
int phai(){
    if(tontan[rightTonTan].v==vuate[rightVuaTe].v)return 0;
    else if(tontan[rightTonTan].v>vuate[rightVuaTe].v)return 1;
    return -1;
}
int dieukien(){
    return rightTonTan>=leftTonTan && rightVuaTe>=leftVuaTe;
}
void process(){
    do{
        while(dieukien() && phai()==1){
            trace[vuate[rightVuaTe].id]=tontan[rightTonTan].id;
            rightTonTan--;
            rightVuaTe--;
        }
        while(dieukien() && trai()==-1){
            trace[vuate[rightVuaTe].id]=tontan[leftTonTan].id;
            leftTonTan++;
            rightVuaTe--;
        }
        while(dieukien() && trai()==0 && phai()<=0){
            trace[vuate[rightVuaTe].id]=tontan[leftTonTan].id;
            leftTonTan++;
            rightVuaTe--;
        }
        while(dieukien() && trai()==1){
            trace[vuate[leftVuaTe].id]=tontan[leftTonTan].id;
            leftVuaTe++;
            leftTonTan++;
        }    
    }while(dieukien());
}
void output(){
    FILE *fp=fopen("RACE.OUT","w");
    for(i=0;i<n;i++){
        fprintf(fp,"%ld %ld",trace[i]+1,i+1);
        if(i<n)fprintf(fp,"\n");
    }
    fclose(fp);
}
            
int main(){
    input();
    process();
    output();
    return 0;
}
